<?php

class AliasetController extends GxController {

public function filters() {
	return array(
			'accessControl', 
			);
}

public function accessRules() {
	return array(
			array('allow',
				'actions'=>array('index','view'),
				'users'=>array('*'),
				),
			array('allow', 
				'actions'=>array('minicreate', 'create','update'),
				'users'=>array('@'),
				),
			array('allow', 
				'actions'=>array('admin','delete'),
				'users'=>array('admin'),
				),
			array('deny', 
				'users'=>array('*'),
				),
			);
}

	public function actionView($id) {
                $this->layout = '//layouts/column3';
		$this->render('view', array(
			'model' => $this->loadModel($id, 'AliasEtiquetasAdicionales'),
		));
	}

	public function actionCreate($campo="") {
                $this->layout = '//layouts/column3';
		$model = new AliasEtiquetasAdicionales;
                if(is_numeric($campo)){
                      $model->ALS_ID=$campo;
                }
		$this->performAjaxValidation($model, 'alias-etiquetas-adicionales-form');
                Controller::registrar_scrips();
                Controller::registrar_scrips_jquery();
		if (isset($_POST['AliasEtiquetasAdicionales'])) {
			$model->setAttributes($_POST['AliasEtiquetasAdicionales']);

			if ($model->save()) {
				if (Yii::app()->getRequest()->getIsAjaxRequest())
					Yii::app()->end();
				else
					$this->redirect(array('view', 'id' => $model->AEAID));
			}
		}

		$this->render('create', array( 'model' => $model));
	}

	public function actionUpdate($id) {
                $this->layout = '//layouts/column3';
		$model = $this->loadModel($id, 'AliasEtiquetasAdicionales');

		$this->performAjaxValidation($model, 'alias-etiquetas-adicionales-form');
                Controller::registrar_scrips();
                Controller::registrar_scrips_jquery();
		if (isset($_POST['AliasEtiquetasAdicionales'])) {
			$model->setAttributes($_POST['AliasEtiquetasAdicionales']);

			if ($model->save()) {
				$this->redirect(array('view', 'id' => $model->AEAID));
			}
		}

		$this->render('update', array(
				'model' => $model,
				));
	}

	public function actionDelete($id,$campo="") {
                $this->layout = '//layouts/column3';
		if (Yii::app()->getRequest()->getIsPostRequest()) {
			$this->loadModel($id, 'AliasEtiquetasAdicionales')->delete();

			if (!Yii::app()->getRequest()->getIsAjaxRequest())
				$this->redirect(array('admin', 'campo'=>$campo));
		} else
			throw new CHttpException(400, Yii::t('app', 'Your request is invalid.'));
	}

	public function actionIndex($campo="") {
                $this->layout = '//layouts/column3';
                $condicion="";
                if(is_numeric($campo))
                    $condicion= "ALS_ID=$campo";
                
		$dataProvider = new CActiveDataProvider('AliasEtiquetasAdicionales', array('criteria'=>array(
                    'condition'=>$condicion,
                    'order'=>'AEAID DESC',
                    'params'=> $campo),
                ));
		$this->render('index', array(
			'dataProvider' => $dataProvider,
		));
	}

	public function actionAdmin($campo="") {
                $this->layout = '//layouts/column3';
		$model = new AliasEtiquetasAdicionales('search');
		$model->unsetAttributes();
                
                if (is_numeric($campo))
                    $model->ALS_ID=$campo;
                
		if (isset($_GET['AliasEtiquetasAdicionales']))
			$model->setAttributes($_GET['AliasEtiquetasAdicionales']);

		$this->render('admin', array(
			'model' => $model,
		));
	}

}